package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.Admin;
import service.AdminLoginService;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class AdminLogin {
    @RequestMapping("/toaLogin")
    public String initLogin(){
        return "adminLogin";
    }
    @Autowired
    private AdminLoginService adminLoginService;
    @RequestMapping("/alogin")
    public String login(Integer aid, String apwd, HttpSession session,Model model){
        List<Admin> adminList=adminLoginService.log(aid,apwd);
        if(adminList.size()!=0){
            session.setAttribute("adminList",adminList);
            return "adminManagePage";
        }
        model.addAttribute("msg","管理员名或密码错误！");
        return "adminLogin";
    }
    @RequestMapping("/toMan")
    public String initMan(){return "adminManagePage";}
    @RequestMapping("/alogOut")
    public String logOut(HttpSession session){
        session.invalidate();
        return "adminLogin";
    }
}
